package com.glorysoft.xztpda.ui.lotcomment

import com.glorysoft.xztpda.base.BaseViewModel
import com.glorysoft.xztpda.entity.LotInfoEntity
import com.glorysoft.xztpda.entity.LotList
import com.glorysoft.xztpda.model.LotRepository
import com.google.gson.Gson
import com.google.gson.JsonObject
import com.google.gson.JsonParser
import java.util.ArrayList

/**
 * FileName: LotCommentViewModel
 * Author: XJH
 * Date: 2022/4/20 11:34
 * Description:
 * History:
 */
class LotCommentViewModel : BaseViewModel() {

    private val repository : LotRepository = LotRepository()
    var lotInfoEntity : LotInfoEntity? = null


    fun getLotInfo(lot: String){
        val map = JsonObject()
        map.addProperty("ACTIONTYPE","LOTINFOBYID")
        map.addProperty("LOTID",lot)
        map.addProperty("EQUIPMENTID","")
        launchOnlyResult({
            lotInfoEntity = repository.getLotInfo(map)
            defUI.callObserve.call()
        })

    }


    fun putLotComment(comment : String){
        val map = JsonObject()
        map.addProperty("ACTIONTYPE","LotExcMemorandum")
        map.addProperty("LOTID",lotInfoEntity?.lot?.lotid)
        map.addProperty("LOTQTY",lotInfoEntity?.lot?.mainqty)
        map.addProperty("LOTSTATE",lotInfoEntity?.lot?.state)
        map.addProperty("CURRENTSTEP",lotInfoEntity?.lot?.stepname)
        map.addProperty("COMMENTS",comment)
        val lotList: MutableList<LotList> = ArrayList<LotList>()
        lotList.add(LotList(lotInfoEntity?.lot?.lotid))
        map.add("LOTLIST", JsonParser().parse(Gson().toJson(lotList)).asJsonArray)
        launchOnlyResult({
            repository.putLotComment(map)
            defUI.startActivity.call()
        })
    }



}